package cn.zxinrun.core.exception;

import lombok.Getter;

/**
 * 系统业务异常类
 * @author Mr.Zhang
 * @since 1.0
 **/
@Getter
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 错误明细，内部调试错误
     */
    private String detailMessage;

    /**
     * 空构造方法，避免反序列化问题
     */
    public ServiceException() {
    }

    /**
     * 构造方法
     * @param message 错误提示
     */
    public ServiceException(String message) {
        this.message = message;
    }

    /**
     * 构造方法
     * @param message 错误提示
     * @param code    错误码
     */
    public ServiceException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    /**
     * 构造方法
     * @param message       错误提示
     * @param code          错误码
     * @param detailMessage 错误明细
     */
    public ServiceException(String message, Integer code, String detailMessage) {
        this.message = message;
        this.code = code;
        this.detailMessage = detailMessage;
    }

    /**
     * 设置错误提示
     * @param message 错误提示
     * @return ServiceException
     */
    public ServiceException setMessage(String message) {
        this.message = message;
        return this;
    }

    /**
     * 设置错误明细
     * @param detailMessage 错误明细
     * @return ServiceException
     */
    public ServiceException setDetailMessage(String detailMessage) {
        this.detailMessage = detailMessage;
        return this;
    }

}
